package org.tio.sitexxx.service.service.qj;

import com.alibaba.fastjson.JSON;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.sitexxx.service.model.main.Retail;
import org.tio.sitexxx.service.vo.Const;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class RetailService {
    private static Logger log	= LoggerFactory.getLogger(RetailService.class);
    public static final RetailService me	= new RetailService();
    final Retail dao	= new Retail().dao();
    public RetailService(){

    }
    public boolean createRetail(Retail retail){
        return retail.save();

    }
    public boolean checkRetail(String mobile){
        List<Retail>resultList=new ArrayList<>(6);

        String sqlid = "retail.checkRetail";
        String db = Const.Db.TIO_SITE_MAIN;
//        Member list = Member.dao.findFirst(sql, openid);
        SqlPara sqlPara = Db.use(db).getSqlPara(sqlid,mobile);
        List<Record> record = Db.use(db).find(sqlPara);
        for(Record record1: record){
            resultList.add(JSON.parseObject(JSON.toJSONString(record1.getColumns()),Retail.class));

        }
        return resultList.size()==0;
    }
    public Retail findRetail(Map<String,Object> query){
        String mobile=query.get("mobile").toString();
        String password=query.get("password").toString();
        String sqlid = "retail.checkRetail";
        String db = Const.Db.TIO_SITE_MAIN;
//        Member list = Member.dao.findFirst(sql, openid);
        SqlPara sqlPara = Db.use(db).getSqlPara(sqlid,mobile,password);
        Record retail= Db.use(db).findFirst(sqlPara.getSql());
        Retail retail1=JSON.parseObject(JSON.toJSONString(retail.getColumns()),Retail.class);

        return retail1;

    }

}
